package net.yeah.mickey_zhouyou.util.fcs.elem;

import java.io.IOException;

import javax.script.ScriptContext;

import net.yeah.mickey_zhouyou.util.fcs.ReaderOverException;
import net.yeah.mickey_zhouyou.util.fcs.ReaderWrapper;
import net.yeah.mickey_zhouyou.util.fcs.SyntaxException;
import net.yeah.mickey_zhouyou.util.fcs.serialize.IConvertor;

public class Fcs {
	private Sentence firstSentence;
	private Fcs fcs;

	public static Fcs create(ReaderWrapper reader) throws IOException {
		Sentence sentence = Sentence.create(reader);
		if (sentence != null) {
			Fcs res = new Fcs();
			res.firstSentence = sentence;
			char b;
			try {
				b = reader.readNotBlank();
			} catch (ReaderOverException e) {
				return res;
			}
			if (b == ';')
				res.fcs = create(reader);
			else
				throw new SyntaxException("读取第二个句子失败", reader.getCurrentRow(),
						reader.getCurrentColumn());
			return res;
		}
		return null;
	}

	public void eval(IConvertor objConvertor, ScriptContext context) {
		this.firstSentence.eval(objConvertor, context);
		if (this.fcs != null)
			this.fcs.eval(objConvertor, context);
	}
}
